/**
 * Vektorrechnung 2D.
 * 
 * 
 */

public class Vector {
	private double _v1;
	private double _v2;
	private double _v3;
	private char _name;

	public Vector(Point p1, Point p2) {
		_v1 = p2.getX() - p1.getX();
		_v2 = p2.getY() - p1.getY();
		_v3 = p2.getZ() - p1.getZ();
		_name = 'v';

	}

	public Vector(Point p) {
		this(new Point(), p);
	}

	public Vector(double angleX, double angleY, double length) {
		// Calculations may not correct
		_v1 = Math.cos(angleX) * length;
		_v2 = Math.sin(angleX) * length;
		_v3 = Math.cos(angleY) * length;
	}

	public Vector calcCrossProduct(Vector v) {
		double v1 = _v2 * v._v3 - _v3 * v._v2;
		double v2 = _v3 * v._v1 - _v1 * v._v3;
		double v3 = _v1 * v._v2 - _v2 * v._v1;
		return (new Vector(new Point(v1, v2, v3)));
	}

	public Vector calcNormalVectorOfPolygon(Vector v) {
		return calcCrossProduct(v);
	}

	public double getLength() {
		return (Math.sqrt(_v1 * _v1 + _v2 * _v2 + _v3 * _v3));
	}

	public double calcScalarProduct(Vector v) {
		return (v._v1 * _v1 + v._v2 * _v2 + v._v3 * _v3);

	}

	public void setName(char name) {
		_name = name;
	}

	public String toString() {
		return ("     / " + _v1 + " \\\n" + _name + " = |  " + _v2 + "  |\n"
				+ "     \\ " + _v3 + " /");
	}

}
